﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SaludOcupacional.Model;
using System.Collections.ObjectModel;
using SaludOcupacional.Controller;

namespace SaludOcupacional
{
    /// <summary>
    /// Interaction logic for Cronogramas.xaml
    /// </summary>
    public partial class Cronogramas : Window
    {

        private Empleado Empleado;
        public Cronogramas(Empleado empleado)
        {
            InitializeComponent();
            Empleado = empleado;

            rNombre.Content = empleado.Nombre + " " + empleado.ApellidoPaterno + " " + empleado.ApellidoMaterno;
            rCodigo.Content = empleado.Codigo;
            eNombre.Content = empleado.Nombre + " " + empleado.ApellidoPaterno + " " + empleado.ApellidoMaterno;
            eCodigo.Content = empleado.Codigo;
            vNombre.Content = empleado.Nombre + " " + empleado.ApellidoPaterno + " " + empleado.ApellidoMaterno;
            vCodigo.Content = empleado.Codigo;

                      
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (rComboBox.Text == "")
                {
                    MessageBox.Show("Ingrese El Analisis");
                }
                else
                {
                    if (rFecha.Text == "" || rFecha.Text == null)
                    {
                        MessageBox.Show("Ingrese La fecha");
                    }
                    else
                    {
                        CronogramasManager.VerificarAnalisis(Empleado.Ci, rComboBox.Text);

                        Cronograma cronograma = new Cronograma(0, Empleado.Ci, rFecha.Text.ToString(), rComboBox.Text);

                        CronogramasManager.CrearCita(cronograma);

                        MessageBox.Show("Se Registro La Cita!");

                        rComboBox.Text = "";
                    }

                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Collection<Cronograma> lista = new Collection<Cronograma>();
                lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

                vCalendar = new Calendar();

                if (lista.Count > 0)
                {
                    int i = 0;
                    analisis1.Visibility = Visibility.Visible;
                    analisis1.Content = lista[i].Analisis;
                    fecha1.Visibility = Visibility.Visible;
                    fecha1.Content = lista[i].Fecha;
                    
      

                    i++;

                    if (lista.Count > 1)
                    {
                        analisis2.Visibility = Visibility.Visible;
                        analisis2.Content = lista[i].Analisis;
                        fecha2.Visibility = Visibility.Visible;
                        fecha2.Content = lista[i].Fecha;
                       
                    }

                    else
                    {
                        analisis2.Visibility = Visibility.Hidden;
                        fecha2.Visibility = Visibility.Hidden;

                        analisis3.Visibility = Visibility.Hidden;
                        fecha3.Visibility = Visibility.Hidden;

                        analisis4.Visibility = Visibility.Hidden;
                        fecha4.Visibility = Visibility.Hidden;

                        analisis5.Visibility = Visibility.Hidden;
                        fecha5.Visibility = Visibility.Hidden;

                        analisis6.Visibility = Visibility.Hidden;
                        fecha6.Visibility = Visibility.Hidden;

                        

                    }
                    i++;
                    if (lista.Count > 2)
                    {
                        analisis3.Visibility = Visibility.Visible;
                        analisis3.Content = lista[i].Analisis;
                        fecha3.Visibility = Visibility.Visible;
                        fecha3.Content = lista[i].Fecha;
                        
                    }
                    else
                    {

                        analisis3.Visibility = Visibility.Hidden;
                        fecha3.Visibility = Visibility.Hidden;

                        analisis4.Visibility = Visibility.Hidden;
                        fecha4.Visibility = Visibility.Hidden;

                        analisis5.Visibility = Visibility.Hidden;
                        fecha5.Visibility = Visibility.Hidden;

                        analisis6.Visibility = Visibility.Hidden;
                        fecha6.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 3)
                    {
                        analisis4.Visibility = Visibility.Visible;
                        analisis4.Content = lista[i].Analisis;
                        fecha4.Visibility = Visibility.Visible;
                        fecha4.Content = lista[i].Fecha;
                        
                    }
                    else
                    {


                        analisis4.Visibility = Visibility.Hidden;
                        fecha4.Visibility = Visibility.Hidden;

                        analisis5.Visibility = Visibility.Hidden;
                        fecha5.Visibility = Visibility.Hidden;

                        analisis6.Visibility = Visibility.Hidden;
                        fecha6.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 4)
                    {
                        analisis5.Visibility = Visibility.Visible;
                        analisis5.Content = lista[i].Analisis;
                        fecha5.Visibility = Visibility.Visible;
                        fecha5.Content = lista[i].Fecha;
                       
                    }
                    else
                    {

                        analisis5.Visibility = Visibility.Hidden;
                        fecha5.Visibility = Visibility.Hidden;

                        analisis6.Visibility = Visibility.Hidden;
                        fecha6.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 5)
                    {
                        analisis6.Visibility = Visibility.Visible;
                        analisis6.Content = lista[i].Analisis;
                        fecha6.Visibility = Visibility.Visible;
                        fecha6.Content = lista[i].Fecha;
                        
                    }
                    else
                    {

                        analisis6.Visibility = Visibility.Hidden;
                        fecha6.Visibility = Visibility.Hidden;
                    }

                }
                else
                {
                    analisis1.Visibility = Visibility.Hidden;
                    fecha1.Visibility = Visibility.Hidden;

                    analisis2.Visibility = Visibility.Hidden;
                    fecha2.Visibility = Visibility.Hidden;

                    analisis3.Visibility = Visibility.Hidden;
                    fecha3.Visibility = Visibility.Hidden;

                    analisis4.Visibility = Visibility.Hidden;
                    fecha4.Visibility = Visibility.Hidden;

                    analisis5.Visibility = Visibility.Hidden;
                    fecha5.Visibility = Visibility.Hidden;

                    analisis6.Visibility = Visibility.Hidden;
                    fecha6.Visibility = Visibility.Hidden;



                    MessageBox.Show("No se encontro Resultados!");
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Collection<Cronograma> lista = new Collection<Cronograma>();
                lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);


                if (lista.Count > 0)
                {
                    int i = 0;
                    eanalisis1.Visibility = Visibility.Visible;
                    eanalisis1.Content = lista[i].Analisis;
                    efecha1.Visibility = Visibility.Visible;
                    efecha1.Content = lista[i].Fecha;
                    editar1.Visibility = Visibility.Visible;



                    i++;

                    if (lista.Count > 1)
                    {
                        eanalisis2.Visibility = Visibility.Visible;
                        eanalisis2.Content = lista[i].Analisis;
                        efecha2.Visibility = Visibility.Visible;
                        efecha2.Content = lista[i].Fecha;
                        editar2.Visibility = Visibility.Visible;

                    }

                    else
                    {
                        eanalisis2.Visibility = Visibility.Hidden;
                        efecha2.Visibility = Visibility.Hidden;
                        editar2.Visibility = Visibility.Hidden;
                        fec2.Visibility = Visibility.Hidden;
                        cambiar2.Visibility = Visibility.Hidden;

                        eanalisis3.Visibility = Visibility.Hidden;
                        efecha3.Visibility = Visibility.Hidden;
                        editar3.Visibility = Visibility.Hidden;
                        fec3.Visibility = Visibility.Hidden;
                        cambiar3.Visibility = Visibility.Hidden;

                        eanalisis4.Visibility = Visibility.Hidden;
                        efecha4.Visibility = Visibility.Hidden;
                        editar4.Visibility = Visibility.Hidden;
                        fec4.Visibility = Visibility.Hidden;
                        cambiar4.Visibility = Visibility.Hidden;

                        eanalisis5.Visibility = Visibility.Hidden;
                        efecha5.Visibility = Visibility.Hidden;
                        editar5.Visibility = Visibility.Hidden;
                        fec5.Visibility = Visibility.Hidden;
                        cambiar5.Visibility = Visibility.Hidden;

                        eanalisis6.Visibility = Visibility.Hidden;
                        efecha6.Visibility = Visibility.Hidden;
                        editar6.Visibility = Visibility.Hidden;
                        fec6.Visibility = Visibility.Hidden;
                        cambiar6.Visibility = Visibility.Hidden;



                    }
                    i++;
                    if (lista.Count > 2)
                    {
                        eanalisis3.Visibility = Visibility.Visible;
                        eanalisis3.Content = lista[i].Analisis;
                        efecha3.Visibility = Visibility.Visible;
                        efecha3.Content = lista[i].Fecha;
                        editar3.Visibility = Visibility.Visible;

                    }
                    else
                    {

                        eanalisis3.Visibility = Visibility.Hidden;
                        efecha3.Visibility = Visibility.Hidden;
                        editar3.Visibility = Visibility.Hidden;
                        fec3.Visibility = Visibility.Hidden;
                        cambiar3.Visibility = Visibility.Hidden;

                        eanalisis4.Visibility = Visibility.Hidden;
                        efecha4.Visibility = Visibility.Hidden;
                        editar4.Visibility = Visibility.Hidden;
                        fec4.Visibility = Visibility.Hidden;
                        cambiar4.Visibility = Visibility.Hidden;

                        eanalisis5.Visibility = Visibility.Hidden;
                        efecha5.Visibility = Visibility.Hidden;
                        editar5.Visibility = Visibility.Hidden;
                        fec5.Visibility = Visibility.Hidden;
                        cambiar5.Visibility = Visibility.Hidden;

                        eanalisis6.Visibility = Visibility.Hidden;
                        efecha6.Visibility = Visibility.Hidden;
                        editar6.Visibility = Visibility.Hidden;
                        fec6.Visibility = Visibility.Hidden;
                        cambiar6.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 3)
                    {
                        eanalisis4.Visibility = Visibility.Visible;
                        eanalisis4.Content = lista[i].Analisis;
                        efecha4.Visibility = Visibility.Visible;
                        efecha4.Content = lista[i].Fecha;
                        editar4.Visibility = Visibility.Visible;

                    }
                    else
                    {

                        eanalisis4.Visibility = Visibility.Hidden;
                        efecha4.Visibility = Visibility.Hidden;
                        editar4.Visibility = Visibility.Hidden;
                        fec4.Visibility = Visibility.Hidden;
                        cambiar4.Visibility = Visibility.Hidden;

                        eanalisis5.Visibility = Visibility.Hidden;
                        efecha5.Visibility = Visibility.Hidden;
                        editar5.Visibility = Visibility.Hidden;
                        fec5.Visibility = Visibility.Hidden;
                        cambiar5.Visibility = Visibility.Hidden;

                        eanalisis6.Visibility = Visibility.Hidden;
                        efecha6.Visibility = Visibility.Hidden;
                        editar6.Visibility = Visibility.Hidden;
                        fec6.Visibility = Visibility.Hidden;
                        cambiar6.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 4)
                    {
                        eanalisis5.Visibility = Visibility.Visible;
                        eanalisis5.Content = lista[i].Analisis;
                        efecha5.Visibility = Visibility.Visible;
                        efecha5.Content = lista[i].Fecha;
                        editar5.Visibility = Visibility.Visible;

                    }
                    else
                    {

                        eanalisis5.Visibility = Visibility.Hidden;
                        efecha5.Visibility = Visibility.Hidden;
                        editar5.Visibility = Visibility.Hidden;
                        fec5.Visibility = Visibility.Hidden;
                        cambiar5.Visibility = Visibility.Hidden;

                        eanalisis6.Visibility = Visibility.Hidden;
                        efecha6.Visibility = Visibility.Hidden;
                        editar6.Visibility = Visibility.Hidden;
                        fec6.Visibility = Visibility.Hidden;
                        cambiar6.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 5)
                    {
                        eanalisis6.Visibility = Visibility.Visible;
                        eanalisis6.Content = lista[i].Analisis;
                        efecha6.Visibility = Visibility.Visible;
                        efecha6.Content = lista[i].Fecha;
                        editar6.Visibility = Visibility.Visible;

                    }
                    else
                    {

                        eanalisis6.Visibility = Visibility.Hidden;
                        efecha6.Visibility = Visibility.Hidden;
                        editar6.Visibility = Visibility.Hidden;
                        fec6.Visibility = Visibility.Hidden;
                        cambiar6.Visibility = Visibility.Hidden;
                    }

                }
                else
                {
                    eanalisis1.Visibility = Visibility.Hidden;
                    efecha1.Visibility = Visibility.Hidden;
                    editar1.Visibility = Visibility.Hidden;
                    fec1.Visibility = Visibility.Hidden;
                    cambiar1.Visibility = Visibility.Hidden;

                    eanalisis2.Visibility = Visibility.Hidden;
                    efecha2.Visibility = Visibility.Hidden;
                    editar2.Visibility = Visibility.Hidden;
                    fec2.Visibility = Visibility.Hidden;
                    cambiar2.Visibility = Visibility.Hidden;

                    eanalisis3.Visibility = Visibility.Hidden;
                    efecha3.Visibility = Visibility.Hidden;
                    editar3.Visibility = Visibility.Hidden;
                    fec3.Visibility = Visibility.Hidden;
                    cambiar3.Visibility = Visibility.Hidden;

                    eanalisis4.Visibility = Visibility.Hidden;
                    efecha4.Visibility = Visibility.Hidden;
                    editar4.Visibility = Visibility.Hidden;
                    fec4.Visibility = Visibility.Hidden;
                    cambiar4.Visibility = Visibility.Hidden;

                    eanalisis5.Visibility = Visibility.Hidden;
                    efecha5.Visibility = Visibility.Hidden;
                    editar5.Visibility = Visibility.Hidden;
                    fec5.Visibility = Visibility.Hidden;
                    cambiar5.Visibility = Visibility.Hidden;

                    eanalisis6.Visibility = Visibility.Hidden;
                    efecha6.Visibility = Visibility.Hidden;
                    editar6.Visibility = Visibility.Hidden;
                    fec6.Visibility = Visibility.Hidden;
                    cambiar6.Visibility = Visibility.Hidden;



                    MessageBox.Show("No se encontro Resultados!");
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private void editar1_Click(object sender, RoutedEventArgs e)
        {
            Collection<Cronograma> lista = new Collection<Cronograma>();
            lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

            fec1.Visibility = Visibility.Visible;
            cambiar1.Visibility = Visibility.Visible;

            fec1.Text = lista[0].Fecha;
        }

        private void editar2_Click(object sender, RoutedEventArgs e)
        {
            Collection<Cronograma> lista = new Collection<Cronograma>();
            lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

            fec2.Visibility = Visibility.Visible;
            cambiar2.Visibility = Visibility.Visible;

            fec2.Text = lista[1].Fecha;
        }

        private void editar3_Click(object sender, RoutedEventArgs e)
        {
            Collection<Cronograma> lista = new Collection<Cronograma>();
            lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

            fec3.Visibility = Visibility.Visible;
            cambiar3.Visibility = Visibility.Visible;

            fec3.Text = lista[2].Fecha;
        }

        private void editar4_Click(object sender, RoutedEventArgs e)
        {
            Collection<Cronograma> lista = new Collection<Cronograma>();
            lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

            fec4.Visibility = Visibility.Visible;
            cambiar4.Visibility = Visibility.Visible;

            fec4.Text = lista[3].Fecha;
        }

        private void editar5_Click(object sender, RoutedEventArgs e)
        {
            Collection<Cronograma> lista = new Collection<Cronograma>();
            lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

            fec5.Visibility = Visibility.Visible;
            cambiar5.Visibility = Visibility.Visible;

            fec5.Text = lista[3].Fecha;
        }

        private void editar6_Click(object sender, RoutedEventArgs e)
        {
            Collection<Cronograma> lista = new Collection<Cronograma>();
            lista = CronogramasManager.BuscarCitasPorCi(Empleado.Ci);

            fec6.Visibility = Visibility.Visible;
            cambiar6.Visibility = Visibility.Visible;

            fec6.Text = lista[5].Fecha;
        }

        private void cambiar1_Click(object sender, RoutedEventArgs e)
        {
            Cronograma cronograma = new Cronograma(0,Empleado.Ci, fec1.Text.ToString(), eanalisis1.Content.ToString());
            CronogramasManager.EditarCronograma(cronograma);

            fec1.Visibility = Visibility.Hidden;
            cambiar1.Visibility = Visibility.Hidden;

            MessageBox.Show("Cambio realizado!");

            button3_Click(sender, e);
        }

        private void cambiar2_Click(object sender, RoutedEventArgs e)
        {
            Cronograma cronograma = new Cronograma(0, Empleado.Ci, fec2.Text.ToString(), eanalisis2.Content.ToString());
            CronogramasManager.EditarCronograma(cronograma);

            fec2.Visibility = Visibility.Hidden;
            cambiar2.Visibility = Visibility.Hidden;

            MessageBox.Show("Cambio realizado!");

            button3_Click(sender, e);
        }

        private void cambiar3_Click(object sender, RoutedEventArgs e)
        {
            Cronograma cronograma = new Cronograma(0, Empleado.Ci, fec3.Text.ToString(), eanalisis3.Content.ToString());
            CronogramasManager.EditarCronograma(cronograma);

            fec3.Visibility = Visibility.Hidden;
            cambiar3.Visibility = Visibility.Hidden;

            MessageBox.Show("Cambio realizado!");

            button3_Click(sender, e);
        }

        private void cambiar4_Click(object sender, RoutedEventArgs e)
        {
            Cronograma cronograma = new Cronograma(0, Empleado.Ci, fec4.Text.ToString(), eanalisis4.Content.ToString());
            CronogramasManager.EditarCronograma(cronograma);

            fec4.Visibility = Visibility.Hidden;
            cambiar4.Visibility = Visibility.Hidden;

            MessageBox.Show("Cambio realizado!");

            button3_Click(sender, e);
        }

        private void cambiar5_Click(object sender, RoutedEventArgs e)
        {
            Cronograma cronograma = new Cronograma(0, Empleado.Ci, fec5.Text.ToString(), eanalisis5.Content.ToString());
            CronogramasManager.EditarCronograma(cronograma);

            fec5.Visibility = Visibility.Hidden;
            cambiar5.Visibility = Visibility.Hidden;

            MessageBox.Show("Cambio realizado!");

            button3_Click(sender, e);
        }

        private void cambiar6_Click(object sender, RoutedEventArgs e)
        {
            Cronograma cronograma = new Cronograma(0, Empleado.Ci, fec6.Text.ToString(), eanalisis6.Content.ToString());
            CronogramasManager.EditarCronograma(cronograma);

            fec6.Visibility = Visibility.Hidden;
            cambiar6.Visibility = Visibility.Hidden;

            MessageBox.Show("Cambio realizado!");

            button3_Click(sender, e);
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }


    }
}
